#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from PageFaultSequence import PageFaultSequence
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU
from gpgpu.ModifierUtils import PageFaultModifier


# This test verifies recovery from a page fault on a branch operation.
class MainSequence(PageFaultSequence):
    def __init__(self, gen_thread, name=None):
        super().__init__(gen_thread, name)
        self._mInstrList = (
            "JAL##CALM",
            "JALR##CALM",
            "LD##CALM",
            "SD##CALM",
            "LW##CALM",
            "SW##CALM",
            "LH##CALM",
            "SH##CALM",
            "LB##CALM",
            "SB##CALM",
        )
        self._mExceptionCodes = [
            12,
            13,
            15,
        ]  # exception code for instr, load, storeamo page fault
        self._mExceptionSubCodes = {}  # N/A

    # Create an instance of the appropriate page fault modifier.
    def createPageFaultModifier(self):
        return PageFaultModifier(self.genThread, self.getGlobalState("AppRegisterWidth"))

    # Return the tuple of instructions to choose from to trigger a page fault.
    def getInstructionList(self):
        return self._mInstrList

    # Return exception codes that can be generated from faulting instructions.
    def getExceptionCodes(self):
        return self._mExceptionCodes


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
